package com.ruoyi.web.controller.model;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.model.manager.domain.TableNode;
import com.ruoyi.model.manager.service.ITableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class TableController extends BaseController {

    @Resource
    private ITableService tableServiceImpl;

    @GetMapping("/tables")
    public AjaxResult getTableTree(@RequestParam(required = false,defaultValue = "history") String pattern) {
        return success(tableServiceImpl.getTableTree(pattern));
    }

    @PostMapping("/columnsData")
    public AjaxResult getTableColumnsData(@RequestBody List<TableNode> tables) {
        long startTime = System.currentTimeMillis();
        List<JSONObject> tableColumnsData = tableServiceImpl.getTableColumnsData(tables, 1);
        log.info("getTableColumnsData耗时：{}", System.currentTimeMillis() - startTime);
        return success(tableColumnsData);
    }

}
